#ifndef __TREE_H__
#define __TREE_H__

struct node_st {
  struct node_st *left, *right;
  char data[0];
};

typedef struct {
  struct node_st *root;
  int size;
} tree_t;

typedef int (*cmp_t)(const void *data, const void *key);
typedef void (*pri_t)(const void *data);

int tree_init(tree_t **mytree, int size);

int tree_insert(tree_t *mytree, const void *key, cmp_t cmp);

int tree_delete(tree_t *mytree, const void *key, cmp_t cmp);

void *tree_search(const tree_t *mytree, const void *key, cmp_t cmp);

void tree_mid_traval(const tree_t *mytree, pri_t pri);

// 平衡
void tree_balance(tree_t *mytree);

void tree_destroy(tree_t **mytree);

#endif
